package com.standardoperationapp.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.standardoperationapp.R;
import com.standardoperationapp.bean.CilckEventBean;
import com.standardoperationapp.bean.MyAcessDoorBean;
import com.standardoperationapp.global.GlobalVaries;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

public class EmergyListAdapter extends BaseAdapter {
    private List<MyAcessDoorBean.DataBean> list;
    private LayoutInflater mInflater;

    public EmergyListAdapter(Context context, List<MyAcessDoorBean.DataBean> list1) {
        list = list1;
        mInflater = LayoutInflater.from(context);
    }



    public int getCount() {
        return list.size();
    }

    public Object getItem(int position) {
        return list.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public int getItemViewType(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent)
    {
        MyAcessDoorBean.DataBean item = list.get(position);
        ViewHolder viewHolder = null;

        if(convertView == null){
            convertView = mInflater.inflate(R.layout.emergy_listview_item, null);
            viewHolder=new ViewHolder(
                    (View) convertView.findViewById(R.id.list_child_emergy),
                    (TextView) convertView.findViewById(R.id.emergy_tx1),
                    (TextView) convertView.findViewById(R.id.emergy_tx2),
                    (TextView) convertView.findViewById(R.id.emergy_tx3)

            );
            convertView.setTag(viewHolder);
        }
        else{
            viewHolder = (ViewHolder)convertView.getTag();
        }

        viewHolder.txt1.setText(Integer.toString(position+1));
        viewHolder.txt2.setText(item.getDoorName());
        viewHolder.txt3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EventBus.getDefault().post(new CilckEventBean(position,2));

            }
        });

        if ((position % 2) == 1) {
            viewHolder.child.setBackgroundColor(Color.parseColor("#F1F1F1"));
        } else {
            viewHolder.child.setBackgroundColor(Color.WHITE);
        }



        return convertView;
    }

    public void upDta(List<MyAcessDoorBean.DataBean> list) {
        this.list = list;
    }

    class ViewHolder
    {
        protected TextView txt1,txt2,txt3;
        private Button infoBtn;
        protected View child;


        public ViewHolder(View child, TextView no,TextView doorid,TextView info){
            this.child = child;
            this.txt1 = no;
            this.txt2=doorid;
            this.txt3 =info;



        }
    }
}